(() => {
  let $selector = document.querySelector(
    "#mw-content-text > div.mw-parser-output > table > tbody"
  );

  let $trs = $selector.querySelectorAll("tr");

  let list = [];
  for (let i = 0; i < $trs.length; i++) {
    let $tr = $trs[i];
    let name = $tr.querySelector("td:nth-child(1)").innerText;
    let country = $tr.querySelector("td:nth-child(2)").innerText;
    let gdp = $tr.querySelector("td:nth-child(3)").innerText;
    let year = $tr.querySelector("td:nth-child(4)").innerText;

    
    let yearExp = /(\d{4}).*/gi;

    list.push({ name, country, gdp, year: yearExp.exec(year)[1] });
  }

  console.log(JSON.stringify(list));

  let $table = document.createElement("table");
  let names = ["name", "country", "gdp", "year"];

  let tableHtml = [];
  list.map((el) => {
    let $tr = document.createElement("tr");

    let values = [];
    for (let key in names) {
      values.push(names[key]);
    }
    let $trinnerHTML = `<tr>${values
      .map((vel) => {
        return `<td>${el[vel]}</td>`;
      })
      .join("")}</tr>`;

    tableHtml.push($trinnerHTML);
  });
  $table.innerHTML = tableHtml.join("");
  document.body.appendChild($table);
})();
